question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get_origin difference between Python 3.6 and Python 3.7

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jph00commented, Oct 21, 2020

I was always think about this, but it may be a breaking change, so I’m not 100% sure.

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 😃

0reactions
ilevkivskyicommented, Aug 5, 2020

Yea, it would be great if then get_origin from this package would work on 3.6 the same as it does on 3.7 and 3.8.

I was always think about this, but it may be a breaking change, so I’m not 100% sure.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found