
GITHUB . COM {
}
Detected CMS Systems:
- Wordpress (2 occurrences)
Title:
The underscore_attrs_are_private config flag turns __doc__ attribute into a ModelPrivateAttr Β· Issue #2090 Β· pydantic/pydantic
Description:
Checks I added a descriptive title to this issue I have searched (google, github) for similar issues and couldn't find anything I have read and followed the docs and still think this is a bug B...
Website Age:
17 years and 8 months (reg. 2007-10-09).
Matching Content Categories {π}
- Technology & Computing
- Luxury
- Telecommunications
Content Management System {π}
What CMS is github.com built with?
Github.com employs WORDPRESS.
Traffic Estimate {π}
What is the average monthly size of github.com audience?
ππ Tremendous Traffic: 10M - 20M visitors per month
Based on our best estimate, this website will receive around 10,000,019 visitors per month in the current month.
However, some sources were not loaded, we suggest to reload the page to get complete results.
check SE Ranking
check Ahrefs
check Similarweb
check Ubersuggest
check Semrush
How Does Github.com Make Money? {πΈ}
Subscription Packages {π³}
We've located a dedicated page on github.com that might include details about subscription plans or recurring payments. We identified it based on the word pricing in one of its internal links. Below, you'll find additional estimates for its monthly recurring revenues.How Much Does Github.com Make? {π°}
Subscription Packages {π³}
Prices on github.com are in US Dollars ($).
They range from $4.00/month to $21.00/month.
We estimate that the site has approximately 4,989,889 paying customers.
The estimated monthly recurring revenue (MRR) is $20,957,532.
The estimated annual recurring revenues (ARR) are $251,490,385.
Wordpress Themes and Plugins {π¨}
What WordPress theme does this site use?
It is strange but we were not able to detect any theme on the page.
What WordPress plugins does this website use?
It is strange but we were not able to detect any plugins on the page.
Keywords {π}
doc, pydantic, issue, attribute, added, bug, private, class, fix, underscoreattrsareprivate, config, jstavrak, import, sign, modelprivateattr, mymodel, bases, namespace, kwargs, cls, prettywood, commit, references, ignore, valid, samuelcolvin, flag, github, true, docsting, metaclass, navigation, issues, pull, requests, actions, security, turns, closed, docs, python, version, bit, basemodel, mymodelbasemodel, mymodeldoc, current, workaround, docpreservingmodelmetaclassmodelmetaclass, def,
Topics {βοΈ}
config flag underscore_attrs_are_private valid private attribute 37aec41 prettywood mentioned pydantic version c76a5b9 samuelcolvin added comment metadata assignees prettywood added similar issues private attribute __doc__ 'mymodel docsting class config import pydantic __doc__ attribute pydantic v1 samuelcolvin added docs python private attributes underscore_attrs_are_private = true nice day return cls __doc__ = doc metaclass=docpreservingmodelmetaclass ignore `__doc__` ignore __doc__ mymodel docsting doc = cls descriptive title conda-forge standard properties current codebase projects milestone milestone relationships personal information cls = super quick fix current workaround def __new__ metaclass offered type projects v1 doc = namespace underscore_attrs_are_private pydantic added issue modelprivateattr github '__doc__' __doc__
Payment Methods {π}
- Braintree
Questions {β}
- Already have an account?
Schema {πΊοΈ}
DiscussionForumPosting:
context:https://schema.org
headline:The underscore_attrs_are_private config flag turns __doc__ attribute into a ModelPrivateAttr
articleBody:### Checks
* [x] I added a descriptive title to this issue
* [x] I have searched (google, github) for similar issues and couldn't find anything
* [x] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug
<!-- Sorry to sound so draconian, but every second saved replying to issues is time spend improving pydantic :-) -->
# Bug
Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
pydantic version: 1.7.2
pydantic compiled: False
install path: D:\dev\Miniconda3\envs\geoenv\Lib\site-packages\pydantic
python version: 3.8.6 | packaged by conda-forge | (default, Oct 7 2020, 18:22:52) [MSC v.1916 64 bit (AMD64)]
platform: Windows-10-10.0.19041-SP0
optional deps. installed: ['typing-extensions']
```
<!-- or if you're using pydantic prior to v1.3, manually include: OS, python version and pydantic version -->
<!-- Please read the [docs](https://pydantic-docs.helpmanual.io/) and search through issues to
confirm your bug hasn't already been reported. -->
<!-- Where possible please include a self-contained code snippet describing your bug: -->
Pydantic v1.7 introduced the private attributes. But when the config flag `underscore_attrs_are_private` is set to `True`, the model's `__doc__` attribute also becomes a private attribute. Example:
```py
>>> from pydantic import BaseModel
>>> class MyModel(BaseModel):
... """MyModel docsting."""
... class Config:
... underscore_attrs_are_private = True
...
>>> MyModel.__doc__
<member '__doc__' of 'MyModel' objects>
```
My current workaround is to define a new metaclass to handle the issue:
```py
>>> from pydantic import BaseModel
>>> from pydantic.main import ModelMetaclass
>>> from pydantic.fields import ModelPrivateAttr
>>> class DocPreservingModelMetaclass(ModelMetaclass):
... def __new__(mcs, name, bases, namespace, **kwargs):
... cls = super().__new__(mcs, name, bases, namespace, **kwargs)
... if cls.__config__.underscore_attrs_are_private:
... doc = cls.__private_attributes__.pop('__doc__', None)
... if isinstance(doc, ModelPrivateAttr):
... cls.__doc__ = doc.default
... return cls
...
>>> class MyModel(BaseModel, metaclass=DocPreservingModelMetaclass):
... """MyModel docsting."""
... class Config:
... underscore_attrs_are_private = True
...
>>> MyModel.__doc__
'MyModel docsting.'
```
But maybe it would be best if `__doc__` was excluded via `pydantic.utils.is_valid_private_name`, much like the other standard properties are excluded through this method. However, I am not sure if the latter will have other implication in the current codebase.
author:
url:https://github.com/jstavrak
type:Person
name:jstavrak
datePublished:2020-11-04T14:07:47.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:2
url:https://github.com/2090/pydantic/issues/2090
context:https://schema.org
headline:The underscore_attrs_are_private config flag turns __doc__ attribute into a ModelPrivateAttr
articleBody:### Checks
* [x] I added a descriptive title to this issue
* [x] I have searched (google, github) for similar issues and couldn't find anything
* [x] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug
<!-- Sorry to sound so draconian, but every second saved replying to issues is time spend improving pydantic :-) -->
# Bug
Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
pydantic version: 1.7.2
pydantic compiled: False
install path: D:\dev\Miniconda3\envs\geoenv\Lib\site-packages\pydantic
python version: 3.8.6 | packaged by conda-forge | (default, Oct 7 2020, 18:22:52) [MSC v.1916 64 bit (AMD64)]
platform: Windows-10-10.0.19041-SP0
optional deps. installed: ['typing-extensions']
```
<!-- or if you're using pydantic prior to v1.3, manually include: OS, python version and pydantic version -->
<!-- Please read the [docs](https://pydantic-docs.helpmanual.io/) and search through issues to
confirm your bug hasn't already been reported. -->
<!-- Where possible please include a self-contained code snippet describing your bug: -->
Pydantic v1.7 introduced the private attributes. But when the config flag `underscore_attrs_are_private` is set to `True`, the model's `__doc__` attribute also becomes a private attribute. Example:
```py
>>> from pydantic import BaseModel
>>> class MyModel(BaseModel):
... """MyModel docsting."""
... class Config:
... underscore_attrs_are_private = True
...
>>> MyModel.__doc__
<member '__doc__' of 'MyModel' objects>
```
My current workaround is to define a new metaclass to handle the issue:
```py
>>> from pydantic import BaseModel
>>> from pydantic.main import ModelMetaclass
>>> from pydantic.fields import ModelPrivateAttr
>>> class DocPreservingModelMetaclass(ModelMetaclass):
... def __new__(mcs, name, bases, namespace, **kwargs):
... cls = super().__new__(mcs, name, bases, namespace, **kwargs)
... if cls.__config__.underscore_attrs_are_private:
... doc = cls.__private_attributes__.pop('__doc__', None)
... if isinstance(doc, ModelPrivateAttr):
... cls.__doc__ = doc.default
... return cls
...
>>> class MyModel(BaseModel, metaclass=DocPreservingModelMetaclass):
... """MyModel docsting."""
... class Config:
... underscore_attrs_are_private = True
...
>>> MyModel.__doc__
'MyModel docsting.'
```
But maybe it would be best if `__doc__` was excluded via `pydantic.utils.is_valid_private_name`, much like the other standard properties are excluded through this method. However, I am not sure if the latter will have other implication in the current codebase.
author:
url:https://github.com/jstavrak
type:Person
name:jstavrak
datePublished:2020-11-04T14:07:47.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:2
url:https://github.com/2090/pydantic/issues/2090
Person:
url:https://github.com/jstavrak
name:jstavrak
url:https://github.com/jstavrak
name:jstavrak
InteractionCounter:
interactionType:https://schema.org/CommentAction
userInteractionCount:2
interactionType:https://schema.org/CommentAction
userInteractionCount:2
External Links {π}(3)
Analytics and Tracking {π}
- Site Verification - Google
Libraries {π}
- Clipboard.js
- D3.js
- Lodash
- Underscore.js
Emails and Hosting {βοΈ}
Mail Servers:
- aspmx.l.google.com
- alt1.aspmx.l.google.com
- alt2.aspmx.l.google.com
- alt3.aspmx.l.google.com
- alt4.aspmx.l.google.com
Name Servers:
- dns1.p08.nsone.net
- dns2.p08.nsone.net
- dns3.p08.nsone.net
- dns4.p08.nsone.net
- ns-1283.awsdns-32.org
- ns-1707.awsdns-21.co.uk
- ns-421.awsdns-52.com
- ns-520.awsdns-01.net