Comments (4)
Thanks @jamesmallen . I'll look into this later this week as well.
from maps.
unpolished thought:
one way to resolve this would be to have functions responsible for creating the injected methods and these functions could accept the typename as an argument:
# namedfixedkeymap.py
...
@staticmethod
def _make_repr(typename):
def _repr(self): # pragma: no cover
kwargs = ', '.join('{}={!r}'.format(key, value) for key, value in self.items())
return '{}({})'.format(typename, kwargs)
return _repr
...
methods = {
...
'__repr__': NamedFixedKeyMapMeta._make_repr(typename),
...
from maps.
On second thought, I believe the only reason an infinite recursion occurs is because __repr__
is calling itself via super(...).__repr__()
, so I would think the problem is contained to just NamedDict
.
Aside: type(self)
is actually desired in most cases so that subclasses don't have to reimplement methods just to hardcode their name everywhere
@jamesmallen have you witnessed any infinite recursion with maps other than NamedDict
(or ideally an example that currently fails)?
from maps.
@jamesmallen feel free to reopen if you do have other cases beyond NamedDict
where this infinite recursion happens
from maps.
Related Issues (20)
- allow more attributes/methods to be passed in by user? HOT 2
- better convenience functions
- `setup.py` keywords
- replace `__class__` with `type()`
- docs
- include license in PyPI archive
- tag releases on github HOT 2
- methods injected by metaclasses should be staticmethods of those metaclasses
- incorporate hackernews post
- include brandojazz user testamonial on docs
- "mapache" explaination in docs
- user-defined defaults for fields HOT 1
- recursive? HOT 4
- What about __slots__ HOT 2
- exec can't handle certain field names beyond keywords HOT 2
- ICYMI check out immutables by Yury Selivanov
- [Feature Request] FrozenMap.update HOT 2
- collections.defaultdict causes FrozenMap.recurse() to fail
- hasattr raises KeyError for NamedDict HOT 2
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 maps.