Comments (7)
Yes, the allowed forms for base classes and the idioms to use for various
cases are not yet sorted out. I also don't like that mypy has both
Generic[T] and AbstractGeneric[T].
On Wed, Jan 14, 2015 at 11:09 PM, Jukka Lehtosalo [email protected]
wrote:
The PEP should probably mention what happens if a generic class is used as
a base class.Examples to consider:
class StrList(List[str]): ... # StrList is not generic
T = TypeVar('T')
class MyList(List[T]): ... # Mypy requires Generic[T] as a base class, but it's ugly
x = Undefined(MyList[int])
—
Reply to this email directly or view it on GitHub
#41.
--Guido van Rossum (python.org/~guido)
from typing.
See also https://github.com/JukkaL/typing/issues/36 about Generic
and AbstractGeneric
.
from typing.
Currently this is not valid (due to Python semantics):
class A(metaclass=ABCMeta): pass
class B(Generic[T], A): pass # metaclass conflict
This is okay, however:
class A(metaclass=ABCMeta): pass
class B(AbstractGeneric[T], A): pass # good
Maybe we should just replace Generic
with AbstractGeneric
and remove AbstractGeneric
? This way most reasonable inheritance patterns should work okay. With the current mypy approach, inheritance hierarchies are inherently fragile -- if some base class adds ABCMeta
as metaclass (due to adding an abstract base class, for example), it can break subclasses that are generic.
from typing.
So, what shall we do? If at all possible I'd like to only have Generic
.
from typing.
I updated mypy and typing to only have Generic
, which also supports defining ABCs. It seems to be okay to me, but I need to do more testing.
from typing.
Added section 'Arbitrary generic types as base classes' to the PEP. Not closing this issue this yet until somebody has reviewed it.
from typing.
Everything looks good to me, except for #85.
from typing.
Related Issues (20)
- FYI: I removed the "stable" docs version
- Pre-draft proposal: Amend the prior removal of support for unpacking of typevartuples in union. (revisiting pep 646) HOT 1
- PR preview HOT 3
- Outdated stub package guidance HOT 1
- Integrate the Type Stubs document into the spec HOT 1
- Types for "truthy" and "falsy" values HOT 6
- Abstract classmethod returning object of type cls: "is not a supertype of its class" HOT 1
- hello
- Spec: Add PEP 696 (Type parameter defaults) HOT 2
- Spec: Add PEP 705 (Read-only TypedDict items) HOT 3
- Extra key of TypedDict HOT 2
- Reason given for disallowing non-concrete subtype assignment is unsound HOT 10
- Out-of-date description of how to indicate positional-only parameters
- Typing spec should be clearer that type checkers are not expected to support PEP 3141 HOT 22
- Incorporate PEP 483 into the spec HOT 5
- Conformance tests: Add mechanism to allow errors on one of multiple lines HOT 2
- Conformance tests: Add mechanism to ignore errors
- Conformance tests: Align automated and manual scoring
- Introduce a `Language` type to provide consistent language information of strings. HOT 5
- Spec: Version and platform checking underspecified HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typing.