Live data from Hacker News

Ask HN: Good Python codebases to read?

news.ycombinator.com

141–150 of 153 posts

Re: Ask HN: Good Python codebases to read?

#141
post #113

Earlier quoted context omitted.

Spare us the half-baked hackery. List comprehensions and generator expressions have replaced all need for map, filter, and lambdas, and are far more readable. For someone new to Python, halfway through LPTHW, they don't need those things. Hey, maybe you can help me decipher this, I've always wondered exactly what's going on here: https://docs.python.org/2/faq/programming.html#is-it-possibl... # Mandelbrot set print (…

> List comprehensions and generator expressions have replaced all need for map, filter, and lambdas, and are far more readable. I would say that is debatable. Coming from an FP background, I use map, filter and lambdas nearly all of the time because I find it more readable and can easily reason about the code. I have seen some two line list comprehensions and they are far harder for me to read and understand.

OK so let's talk about that, which is more readable?:

  iterable = xrange(10)

  ge = (x*x for x in iterable if not x % 2)

  mf = map(lambda x: x*x, filter(lambda x: not x % 2, iterable))
Assume imap and ifilter from itertools or Python 3 (with range) for equivalence. I'm betting if we ask any person new to Python and new to programming, they'd think the former much more readable than the latter. Yes, we left it in the language for you cranks who think map, filter, and lambda are way better, but it's functionally no different.

Re: Ask HN: Good Python codebases to read?

#142
post #133

Earlier quoted context omitted.

When it comes to maintaining standards in a code base, one needs to be a pedant.

The mentality of someone who thinks that an 89-character line that ends with " # noqa" is better than the 81-character line without that ending because now it passes flake8 is one I'll never understand.

Never seen someone do that. That's pretty bad.

I was more defending being a pedant about whatever coding standards your team agrees upon rather than any specific PEP-8 standard.

It is no problem to increase PyLint's line length limit if your team wants to use something other than the PEP-8 79 character limit.

Re: Ask HN: Good Python codebases to read?

#143
post #135

Earlier quoted context omitted.

Django's source is very high quality. Though due to the large scope of the project, there are necessarily many layers of indirection, which may be a bit daunting for someone who is just starting out. However reading the less abstract parts may help. For instance, the paginator is pretty self contained. https://github.com/django/django/blob/master/django/core/pag...

I really like the API of the framework, unfortunately some of the core elements suffer from being extremely stateful code The "self.thing = bar" in one function that only gets used in some other function ( or even worse something only used in a companion class) pattern is super prevalent. Might just be me but I think a lot of the older code suffers from massive locality problems that makes debugging framework bugs su…

Honestly, I have to agree with you to an extent.

I think a lot of the issues involving overuse of state, are primarily related to using OO when a pure function would suffice. It's just too tempting to dynamically assign attributes to mutable instances.

To be fair, when Django is used properly it isn't usually an issue. Besides the queryset/model API is extremely nice, and at this point very polished.

Re: Ask HN: Good Python codebases to read?

#144

Earlier quoted context omitted.

OK, but in requests they are top-level functions, not methods. Is there anything wrong with the below? I don't think I've seen it done. __shared_docstring_content = """ bar baz """ def f(): "f docstring" pass f.__doc__ += __shared_docstring_content def g(): "g docstring" pass g.__doc__ += __shared_docstring_content

I would do simply """f docstring\n%s""" % _shared_docstring, no need for a separate concatenation. However, I wonder whether sphinx would handle this.

This sort of thing works fine. We use it for pandas all the time.

Re: Ask HN: Good Python codebases to read?

#145

Earlier quoted context omitted.

Norvig's code have several qualities to praise Adherence to Python's best practices / pep-8 are not one of them

PEP 8 itself has the quote "a foolish consistency is the hobgoblin of small minds." It is not intended as a prescriptive standard that everyone needs to follow, just a recommendation.

Yeah, I know that, you need to tell everybody else

I'd rather have Norvig's code solving some IA problem than some perfectly compliant PEP-8 code solving an issue in a naive way

Re: Ask HN: Good Python codebases to read?

#146
youtube-dl: https://github.com/rg3/youtube-dl

I fell in love with this project after discovering I don't need ad-choked, dodgy sites to download Youtube videos/mp3s. It also acts as a catch-all downloader for a huge amount of other video hosting sites, despite the name. If you want to learn how to scrape different videos from many platforms, look at this:

https://github.com/rg3/youtube-dl/tree/master/youtube_dl/ext...

Re: Ask HN: Good Python codebases to read?

#147
post #133

Earlier quoted context omitted.

When it comes to maintaining standards in a code base, one needs to be a pedant.

The mentality of someone who thinks that an 89-character line that ends with " # noqa" is better than the 81-character line without that ending because now it passes flake8 is one I'll never understand.

I don't disagree, but keep in mind that on the large codebase you want to avoid false negative in term of pep8 errors.. I.e. if every time you build you see 100s of errors, you start to ignore those.

Re: Ask HN: Good Python codebases to read?

#148
post #67

Earlier quoted context omitted.

Looks like you did the legwork of listing the params already, so you might as well send a PR with that docstring.

OK, maybe I will open an issue. The obvious concern is how to avoid duplicating the text among the various HTTP verb functions. In theory python allows the docstring to be manipulated via __doc__. However I don't think there is a precedent for using that mechanism to avoid duplication of docstring content that is considered good style, but perhaps someone could correct me if that is wrong.

Pandas does this, and I think it works well, even if it's not entirely transparent in the source.

Re: Ask HN: Good Python codebases to read?

#150
post #140

I would also add *Twisted ( https://github.com/twisted/twisted ) For async python.

I disagree. Twisted is a sprawling codebase, it started as a game library that turned into an async library along the way, you need to read books to get the full documentation, and some of it doesn't even have docstrings or comments.

You are right it is not the best example of an open source project, and for what you say it neither is a good python project example. But is there any other place you can get the hold of working async with python, it may be hard, but you would learn a lot.

But maybe there are other async python projects that I don't know of. If you know of any please post them, I would also like to learn more about the subject.

Post reply on HN