get_origin difference between Python 3.6 and Python 3.7
See original GitHub issueI was hoping that using this package would make it easier to migrate between Python versions as it changes typing implementation. So I started using it with Python 3.6 but now that I tried to use working code on Python 3.6 with Python 3.7 it seems there are differences. For example, the following code:
import typing
import typing_inspect
A = typing.TypeVar('A')
B = typing.TypeVar('B')
C = typing.TypeVar('C')
class Base(typing.Generic[A, B]):
pass
class Foo(Base[A, None]):
pass
class Bar(Foo[A], typing.Generic[A, C]):
pass
class Baz(Bar[float, int]):
pass
print("Bar", typing_inspect.get_origin(Bar))
print("Baz", typing_inspect.get_origin(Baz))
print("Base", typing_inspect.get_origin(Base))
print("Base[float, int]", typing_inspect.get_origin(Base[float, int]))
print("Foo", typing_inspect.get_origin(Foo))
print("Foo[float]", typing_inspect.get_origin(Foo[float]))
In Python 3.6 outputs:
Bar __main__.Bar
Baz __main__.Baz
Base __main__.Base
Base[float, int] __main__.Base
Foo __main__.Foo
Foo[float] __main__.Foo
While in Python 3.7:
Bar None
Baz None
Base None
Base[float, int] <class '__main__.Base'>
Foo None
Foo[float] <class '__main__.Foo'>
I think ideally they should behave the same.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
What's New In Python 3.8 — Python 3.11.1 documentation
This article explains the new features in Python 3.8, compared to 3.7. Python 3.8 was released on October 14, 2019. For full details,...
Read more >What's New In Python 3.7 — Python 3.11.1 documentation
This article explains the new features in Python 3.7, compared to 3.6. Python 3.7 was released on June 27, 2018. For full details,...
Read more >typing — Support for type hints — Python 3.11.1 documentation
This module provides runtime support for type hints. The most fundamental support consists of the types Any , Union , Callable , TypeVar...
Read more >What's New In Python 3.6 — Python 3.11.1 documentation
PEP 498, formatted string literals. PEP 515, underscores in numeric literals. PEP 526, syntax for variable annotations.
Read more >Python Documentation by Version - Python.org
Some previous versions of the documentation remain available online. Use the list below to ... Python 3.7.16, documentation released on 6 December 2022....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I suspect there are a lot more people that aren’t able to use this (or need hacky workarounds) because of the inconsistency with 3.6, than there are people relying on the existing behavior (if any). So I think fixing it would be best.
Just my $0.02 😃
I was always think about this, but it may be a breaking change, so I’m not 100% sure.