
GITHUB . COM {
}
Detected CMS Systems:
- Wordpress (2 occurrences)
Title:
X | Y union syntax breaks GenericModel Β· Issue #4146 Β· pydantic/pydantic
Description:
Bug Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())": pydantic version: 1.9.1 pydantic compiled: True install path: /home/paystone/.local/lib/python3.10/site-packages/pydantic python version: 3.10.2 (main...
Website Age:
17 years and 8 months (reg. 2007-10-09).
Matching Content Categories {π}
- Technology & Computing
- Video & Online Content
- Business & Finance
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 {π}
import, pydantic, class, file, python, line, generic, targett, issue, genericmodel, union, type, commented, thenx, sourcet, typing, int, annotations, dmontagu, syntax, bug, types, typevar, genericsourcet, typeerror, typevarsmap, origintype, sign, version, added, models, relationships, return, concretetype, subscriptable, typesuniontype, source, typevars, working, bidirectionalmultirelationshipgenericmodel, relationshiptargett, bidirectionalmultirelationshipstr, traceback, recent, call, input, locallibpythonsitepackagespydanticgenericspy, preparemodelfieldscreatedmodel, fields, instancetypehints,
Topics {βοΈ}
10/site-packages/pydantic/generics /usr/local/lib/python3 local/lib/python3 list[union[relationship[sourcet venv/lib/python3 dum-dum approach __future__ import annotations unsupported operand type dmontagu edits contributor typing import union evaluate list[str] list[str] % python3 comment metadata assignees typing import generic union[list[datat] thenx edits added syntax mygenericmodel[int] results list[relationship[sourcet import pydantic pydantic v1 bidirectionalmultirelationship model 8/lib/python3 search / pydantic models pydantic version 11 class bidirectionalmultirelationship code runs str typeerror class mygenericmodel pydantic/typing targett = typevar list[datat] list[str] newer python generic[sourcet generic[datat] class relationship woodruffw mentioned issue closed existing issue original issue generic models relationship[sourcet 'type' object type projects source 'typing-extensions'] pydantic/main relationship genericmodel
Payment Methods {π}
- Braintree
Questions {β}
- Already have an account?
- UnionType?
Schema {πΊοΈ}
DiscussionForumPosting:
context:https://schema.org
headline:X | Y union syntax breaks GenericModel
articleBody:# Bug
Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
pydantic version: 1.9.1
pydantic compiled: True
install path: /home/paystone/.local/lib/python3.10/site-packages/pydantic
python version: 3.10.2 (main, Jan 29 2022, 02:55:36) [GCC 10.2.1 20210110]
platform: Linux-5.18.2-arch1-1-x86_64-with-glibc2.31
optional deps. installed: ['typing-extensions']
```
Python 3.10 incorporated [PEP 604](https://peps.python.org/pep-0604/), which added syntax for writing Unions as `X | Y`, instead of `typing.Union[X, Y]`. It seems that when this syntax is used in combination with TypeVars as part of a `GenericModel`, the binding of TypeVars to their types fails.
Below is first a working example using `typing.Union`, followed by a non-working example using `|` syntax, with the stack trace. The example seeks to construct a `Relationship` GenericModel, and a `BidirectionalMultiRelationship` model which contains a list of either `Relationship[A, B]` or `Relationship[B, A]` models:
```py
from typing import Union, Generic, TypeVar
from pydantic.generics import GenericModel
SourceT = TypeVar("SourceT")
TargetT = TypeVar("TargetT")
class Relationship(GenericModel, Generic[SourceT, TargetT]):
source: SourceT
target: TargetT
class BidirectionalMultiRelationship(GenericModel, Generic[SourceT, TargetT]):
relationships: list[Union[Relationship[SourceT, TargetT], Relationship[TargetT, SourceT]]]
BidirectionalMultiRelationship[str, int]
```
```py
from typing import Generic, TypeVar
from pydantic.generics import GenericModel
SourceT = TypeVar("SourceT")
TargetT = TypeVar("TargetT")
class Relationship(GenericModel, Generic[SourceT, TargetT]):
source: SourceT
target: TargetT
class BidirectionalMultiRelationship(GenericModel, Generic[SourceT, TargetT]):
relationships: list[Relationship[SourceT, TargetT] | Relationship[TargetT, SourceT]]
BidirectionalMultiRelationship[str, int]
```
```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [2], in <cell line: 14>()
11 class BidirectionalMultiRelationship(GenericModel, Generic[SourceT, TargetT]):
12 relationships: Relationship[SourceT, TargetT] | Relationship[TargetT, SourceT]
---> 14 BidirectionalMultiRelationship[str, int]
File ~/.local/lib/python3.10/site-packages/pydantic/generics.py:137, in GenericModel.__class_getitem__(cls, params)
133 _generic_types_cache[(cls, params[0])] = created_model
135 # Recursively walk class type hints and replace generic typevars
136 # with concrete types that were passed.
--> 137 _prepare_model_fields(created_model, fields, instance_type_hints, typevars_map)
139 return created_model
File ~/.local/lib/python3.10/site-packages/pydantic/generics.py:356, in _prepare_model_fields(created_model, fields, instance_type_hints, typevars_map)
353 assert field.type_.__class__ is DeferredType, field.type_.__class__
355 field_type_hint = instance_type_hints[key]
--> 356 concrete_type = replace_types(field_type_hint, typevars_map)
357 field.type_ = concrete_type
358 field.outer_type_ = concrete_type
File ~/.local/lib/python3.10/site-packages/pydantic/generics.py:263, in replace_types(type_, type_map)
261 origin_type = getattr(typing, type_._name)
262 assert origin_type is not None
--> 263 return origin_type[resolved_type_args]
265 # We handle pydantic generic models separately as they don't have the same
266 # semantics as "typing" classes or generic aliases
267 if not origin_type and lenient_issubclass(type_, GenericModel) and not type_.__concrete__:
TypeError: 'type' object is not subscriptable
```
On inspection I found that at the point that the exception is thrown, `origin_type` is `types.UnionType`, where it should be `Relationship`.
Apologies if I missed an existing issue for this. I couldn't find anything in my search.
author:
url:https://github.com/squarebridges
type:Person
name:squarebridges
datePublished:2022-06-09T22:27:42.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:9
url:https://github.com/4146/pydantic/issues/4146
context:https://schema.org
headline:X | Y union syntax breaks GenericModel
articleBody:# Bug
Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
pydantic version: 1.9.1
pydantic compiled: True
install path: /home/paystone/.local/lib/python3.10/site-packages/pydantic
python version: 3.10.2 (main, Jan 29 2022, 02:55:36) [GCC 10.2.1 20210110]
platform: Linux-5.18.2-arch1-1-x86_64-with-glibc2.31
optional deps. installed: ['typing-extensions']
```
Python 3.10 incorporated [PEP 604](https://peps.python.org/pep-0604/), which added syntax for writing Unions as `X | Y`, instead of `typing.Union[X, Y]`. It seems that when this syntax is used in combination with TypeVars as part of a `GenericModel`, the binding of TypeVars to their types fails.
Below is first a working example using `typing.Union`, followed by a non-working example using `|` syntax, with the stack trace. The example seeks to construct a `Relationship` GenericModel, and a `BidirectionalMultiRelationship` model which contains a list of either `Relationship[A, B]` or `Relationship[B, A]` models:
```py
from typing import Union, Generic, TypeVar
from pydantic.generics import GenericModel
SourceT = TypeVar("SourceT")
TargetT = TypeVar("TargetT")
class Relationship(GenericModel, Generic[SourceT, TargetT]):
source: SourceT
target: TargetT
class BidirectionalMultiRelationship(GenericModel, Generic[SourceT, TargetT]):
relationships: list[Union[Relationship[SourceT, TargetT], Relationship[TargetT, SourceT]]]
BidirectionalMultiRelationship[str, int]
```
```py
from typing import Generic, TypeVar
from pydantic.generics import GenericModel
SourceT = TypeVar("SourceT")
TargetT = TypeVar("TargetT")
class Relationship(GenericModel, Generic[SourceT, TargetT]):
source: SourceT
target: TargetT
class BidirectionalMultiRelationship(GenericModel, Generic[SourceT, TargetT]):
relationships: list[Relationship[SourceT, TargetT] | Relationship[TargetT, SourceT]]
BidirectionalMultiRelationship[str, int]
```
```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [2], in <cell line: 14>()
11 class BidirectionalMultiRelationship(GenericModel, Generic[SourceT, TargetT]):
12 relationships: Relationship[SourceT, TargetT] | Relationship[TargetT, SourceT]
---> 14 BidirectionalMultiRelationship[str, int]
File ~/.local/lib/python3.10/site-packages/pydantic/generics.py:137, in GenericModel.__class_getitem__(cls, params)
133 _generic_types_cache[(cls, params[0])] = created_model
135 # Recursively walk class type hints and replace generic typevars
136 # with concrete types that were passed.
--> 137 _prepare_model_fields(created_model, fields, instance_type_hints, typevars_map)
139 return created_model
File ~/.local/lib/python3.10/site-packages/pydantic/generics.py:356, in _prepare_model_fields(created_model, fields, instance_type_hints, typevars_map)
353 assert field.type_.__class__ is DeferredType, field.type_.__class__
355 field_type_hint = instance_type_hints[key]
--> 356 concrete_type = replace_types(field_type_hint, typevars_map)
357 field.type_ = concrete_type
358 field.outer_type_ = concrete_type
File ~/.local/lib/python3.10/site-packages/pydantic/generics.py:263, in replace_types(type_, type_map)
261 origin_type = getattr(typing, type_._name)
262 assert origin_type is not None
--> 263 return origin_type[resolved_type_args]
265 # We handle pydantic generic models separately as they don't have the same
266 # semantics as "typing" classes or generic aliases
267 if not origin_type and lenient_issubclass(type_, GenericModel) and not type_.__concrete__:
TypeError: 'type' object is not subscriptable
```
On inspection I found that at the point that the exception is thrown, `origin_type` is `types.UnionType`, where it should be `Relationship`.
Apologies if I missed an existing issue for this. I couldn't find anything in my search.
author:
url:https://github.com/squarebridges
type:Person
name:squarebridges
datePublished:2022-06-09T22:27:42.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:9
url:https://github.com/4146/pydantic/issues/4146
Person:
url:https://github.com/squarebridges
name:squarebridges
url:https://github.com/squarebridges
name:squarebridges
InteractionCounter:
interactionType:https://schema.org/CommentAction
userInteractionCount:9
interactionType:https://schema.org/CommentAction
userInteractionCount:9
External Links {π}(3)
Analytics and Tracking {π}
- Site Verification - Google
Libraries {π}
- Clipboard.js
- D3.js
- Lodash
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