Appearance of the object is that it's an empty dict, with a custom repr that would be solved
See original GitHub issueIf you want I could make a PR that would look like the following:
>>> import holidays
>>> us_holidays = holidays.UnitedStates()
>>> us_holidays
holidays.UnitedStates(country="US", prov=None, state=None)
Wouldn’t this be nice? Let me know if I should make the PR
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Initialize an Empty Dictionary in Python - GeeksforGeeks
Method 1: Use of { } symbol. We can create an empty dictionary object by giving no elements in curly brackets in the...
Read more >Custom Python Dictionaries: Inheriting From dict vs UserDict
In this tutorial, you'll learn how to: Create dictionary-like classes by inheriting from the built-in dict class; Identify common pitfalls that ...
Read more >A python class that acts like dict - Stack Overflow
So far, I have not seen an example that shows how to override the [] operator. So if a [] access function is...
Read more >Python __str__() and __repr__() functions | DigitalOcean
Python __repr__() function returns the object representation in string format. This method is called when repr() function is invoked on the ...
Read more >How can I determine if a dictionary is empty? - Python FAQ
Yes, there are several ways to check if a dictionary is empty. The more standard Python method is to use a Boolean evaluation...
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
Hi @dr-prodigy! Thanks for this awesome library! I recently found it while looking for a solution to an ugly banking-related problem and I appreciate having an elegant solution to it.
I’d like you to reopen the issue, because I agree with @kootenpv’s point. Here’s why:
I found this library looking for a list of holidays in Poland. I didn’t expect it to work, but got intrigued by hundreds of Github stars so I tried it out. So I flick through the README,
pip install
it, import it and try it out in my own way:So… an empty dictionary? “That’s not a way to tell me that Poland isn’t supported!” - I thought. So I looked at the README again, saw that Poland was marked as “None” and almost moved along, assuming it’s just yet another popular Python library that doesn’t seem to work for my use case. Curious why it’s the case though, I looked at the code and found that it seems to make sense. So I tried another approach:
Yay! Maybe I can use it after all then! You’re probably shaking your head in disagreement… rightfully so, because I’m supposed to do something like
datetime.date(2021, 1,1) in holidays.Poland()
. To which I’d normally reply “but what’s the point checking if I already got an empty dict…?”So that’s basically the problem. The
__repr__
is misleading and should be changed. Because right now if you come with a lesser known country such as Poland, you’re kind of used to libraries not working and you might just move along, humbly kind of agreeing with that assumed neglect.Here are the solutions I propose:
__repr__
actually return a string that doesn’t suggest it’s a plain dict,__repr__
(which they probably shouldn’t) and you want to be nice to them, throw a DeprecationWarning that this__repr__
is deprecated and you’d rather say it’s an instance ofholidays.countries.poland.Poland
or something,{}
is misleading and__contains__
is overloaded. Showing it in an interactive example is better than writing it as a part of text as some folks scan through dozens of libraries and might just omit something that doesn’t seem to work,is_holiday()
method, because mixing a misleading__repr__
with overloaded__contains__
might be just a bit too much magic.@dr-prodigy yup! That seems to solve the problem 😃 And once again, thanks for implementing this library!