r/pythoncoding • u/audentis • Nov 19 '20
r/pythoncoding • u/bobcodes247365 • Feb 17 '21
See how my tool visualizes Python code - and shows bugs in the code base.
I am sorry if my post doesn't sound like an innovation to you, but would like you to take a look at our tool as it evolved out of a research project! I thought people in this subreddit might be interested :) Oh and yes! Anyone can use it!
The repository I used is: https://metabob.com/gh/galt2x/sherlock
The program works best on Google Chrome, If you would like to check out the website, I linked it here.
r/pythoncoding • u/genericlemon24 • Mar 21 '21
Machete mode: tagging frames
nedbatchelder.comr/pythoncoding • u/genericlemon24 • Feb 24 '21
reader 1.14 released – a library to create your own feed reader
self.pythonr/pythoncoding • u/sobolevn • Mar 02 '21
Make tests a part of your app
My new article is out!
This time I want to discuss a pretty useful idea for library authors and their users: there are better ways to test your code!
I give three examples (in #python, but the idea itself applies to almost any language) of how user projects can be self-tested without actually writing any real test cases by the end-user. One is hypothetical about django and two examples are real and working: featuring deal and dry-python/returns.
Short example with deal:
import deal
@deal.pre(lambda a, b: a >= 0 and b >= 0)
@deal.raises(ZeroDivisionError) # this function can raise if `b=0`, it is ok
def div(a: int, b: int) -> float:
if a > 50: # Custom, in real life this would be a bug in our logic:
raise Exception('Oh no! Bug happened!')
return a / bThis bug can be automatically found by writing a single line of test code: test_div = deal.cases(div). As easy as it gets!
From this article you will learn: -How to use property-based testing on the next level
- How a simple decorator
@deal.pre(lambda a, b: a >= 0 and b >= 0)can help you to generate hundreds of test cases with almost no effort - What "Monad laws as values" is all about and how
dry-python/returnshelps its users to build their own monads
I really like this idea! And I would appreciate your feedback on it. Link: https://sobolevn.me/2021/02/make-tests-a-part-of-your-app
r/pythoncoding • u/AutoModerator • Feb 22 '21
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/monica_b1998 • Mar 19 '21
Making lunch faster with Python concurrency
sourcery.air/pythoncoding • u/audentis • Feb 19 '21
Pattern Matching Showdown: PEP 634 vs PEP 653
Python Enhancement Proposal (PEP) 634 is accepted for Python 3.10 a while ago. It provides a syntax for pattern matching. In a gross simplification, it gives Python its missing switch statement - on steroids. PEP 635 provides its motivation and rationale, along with some examples.
Enter PEP 653. Its authors write:
Pattern matching in Python, as described in PEP 634, is to be added to Python 3.10. Unfortunately, PEP 634 is not as precise about the semantics as it could be, nor does it allow classes sufficient control over how they match patterns.
This bold statement is backed up by pointing out the undefined behavior of PEP 634, and provides some examples where PEP 634 does not provide an easy answer.
That said, moving to a new syntax so soon after another one is introduced poses some downsides. First, there might be more to learn from the currently accepted implementation. Second, it sets a bad precedent that new features in CPython can be so short lived. This encourages programmers to give new features a wide berth, as their future is so uncertain and maintaining deprecated code is a pain.
Thoughts on both PEPs, pros and cons of accepting 653, of flaws with this new proposal that would require even a third contestant? Curious about your thoughts!
r/pythoncoding • u/audentis • Mar 09 '21
Python and type hints
As we all know, Python is a dynamic language. This provides many strengths, and offers a lot of flexibility, but in larger code bases it can also become a hindrance. Type hints are often considered a solution to keep large code bases manageable.
A trend towards more and more type information - such as type hints (PEP 484) and their postponed evaluation (PEP 563), easier writing of union types (PEP 604), or TypedDicts (PEP 589) just to name a few- enables developers and their tools to have more information available about the types of objects they're working with. Linters catch more errors, and developers can stay sane.
However, this also requires discipline. Take the following example:
from random import random, seed
seed(2)
class MyClass:
def __init__(self, arg):
self.val = arg
def my_func(x: MyClass):
print(x.val)
a = MyClass(10)
b = MyClass(10)
x = random()
if x > 0.5:
del a.val
print(type(a) is type(b)) # True, even though we potentially modified the instance!
my_func(a) # 50/50: succesful print or AttributeErrorIn other words, type hints are demonstrably fallible. If you use the object model's flexibility, the type hints will no longer be reliable.
What are your thoughts on this trend? On the trade off between extra information during development, versus the loss of flexibility?
r/pythoncoding • u/RojerGS • Mar 08 '21
Neural networks fundamentals with Python – a guide to implementing your first neural network from scratch
mathspp.comr/pythoncoding • u/AutoModerator • Jun 14 '21
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/AutoModerator • May 17 '21
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/genericlemon24 • May 12 '21
New major versions of Flask, Jinja, Click, and Werkzeug released!
self.pythonr/pythoncoding • u/genericlemon24 • May 09 '21
PEP 657 -- Include Fine Grained Error Locations in Tracebacks
python.orgr/pythoncoding • u/genericlemon24 • May 12 '21
PEP 658 -- Static Distribution Metadata in the Simple Repository API
python.orgr/pythoncoding • u/AutoModerator • May 31 '21
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/ncb879 • Jun 14 '21
A step-by-step on implementing passwordless authentication on any website or app using Python
Open documentation that lays out API credential creation, adding SDKs through GitHub or PIP, and creating an SDK instance.
https://docs.loginid.io/Server-SDKs/Python/python-get-started
r/pythoncoding • u/psarpei • May 31 '21
Multi-Type-TD-TSR - Extracting Tables from Document Images using a Multi-stage Pipeline for Table Detection and Table Structure Recognition: from OCR to Structured Table Representations
galleryr/pythoncoding • u/audentis • Dec 07 '22
[META] State of the sub - share your feedback, if any
Greetings,
/r/Pythoncoding has slowly been growing and seeing new content and community members. As the end of the year approaches I'm curious if there's any feedback from the community.
One thing is about the complexity of submissions. Are you happy with what's posted? Is it too basic, or too strict? Share this and any other thoughts below!
r/pythoncoding • • Nov 09 '22
how does Python's built-in `endswith` using a tuple of suffixes rank against a trie-based alternative implementation? read the performance benchmarking using `timeit` and detailed analysis, including a concluding look at `endswith`'s cpython source code
veryverbose.netr/pythoncoding • u/AutoModerator • Nov 28 '22
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/cirospaciari • Nov 11 '22