Code for the Python code smells video on the ArjanCodes channel.

Overview

7 Python code smells

This repository contains the code for the Python code smells video on the ArjanCodes channel (watch the video here).

The example is about employees at a company. In before.py, you find the original code (containing 7 code smells + a bonus smell). The after.py file contains the same code, but a lot less smelly.

You might also like...
Code for CodeT5: a new code-aware pre-trained encoder-decoder model.
Code for CodeT5: a new code-aware pre-trained encoder-decoder model.

CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation This is the official PyTorch implementation

Galois is an auto code completer for code editors (or any text editor) based on OpenAI GPT-2.
Galois is an auto code completer for code editors (or any text editor) based on OpenAI GPT-2.

Galois is an auto code completer for code editors (or any text editor) based on OpenAI GPT-2. It is trained (finetuned) on a curated list of approximately 45K Python (~470MB) files gathered from the Github. Currently, it just works properly on Python but not bad at other languages (thanks to GPT-2's power).

Simple python code to fix your combo list by removing any text after a separator or removing duplicate combos

Combo List Fixer A simple python code to fix your combo list by removing any text after a separator or removing duplicate combos Removing any text aft

A python project made to generate code using either OpenAI's codex or GPT-J (Although not as good as codex)

CodeJ A python project made to generate code using either OpenAI's codex or GPT-J (Although not as good as codex) Install requirements pip install -r

Repository of the Code to Chatbots, developed in Python

Description In this repository you will find the Code to my Chatbots, developed in Python. I'll explain the structure of this Repository later. Requir

Python code for ICLR 2022 spotlight paper EViT: Expediting Vision Transformers via Token Reorganizations
Python code for ICLR 2022 spotlight paper EViT: Expediting Vision Transformers via Token Reorganizations

Expediting Vision Transformers via Token Reorganizations This repository contain

Converts python code into c++ by using OpenAI CODEX.

🦾 codex_py2cpp 🤖 OpenAI Codex Python to C++ Code Generator Your Python Code is too slow? 🐌 You want to speed it up but forgot how to code in C++? ⌨

Python module (C extension and plain python) implementing Aho-Corasick algorithm

pyahocorasick pyahocorasick is a fast and memory efficient library for exact or approximate multi-pattern string search meaning that you can find mult

Comments
  • Dataclass Class of 'Dataclass Class'es Python 3.8

    Dataclass Class of 'Dataclass Class'es Python 3.8

    @egges , I follow your video avidly. Thanks ! Have a design related question :

    I have a dataclass of a single class object 'AStock' as such:

    @dataclass
    class AStock:
        
        code_: Union[str, int]
        force_update_: bool = False
        ticker_: str = field(init=False)
        symbol_: str = field(init=False)
        name_: str = field(init=False)
        sector_: str = field(init=False)
        subsector_: str = field(init=False)
        
        @exception(logger)
        def __post_init__(self) -> None:
            try:
                self.code_ = str(self.code_).zfill(4)
                self.ticker_ = indexer(code=self.code_, arg='ticker')
                self.symbol_ = indexer(code=self.code_, arg='symbol')
                self.name_ = indexer(code=self.code_, arg='full_name')
                self.sector_ = indexer(code=self.code_, arg='sector')
                self.subsector_ = indexer(code=self.code_, arg='subsector')
    
            except NoStockFound:
                raise
            except Exception as e:
                raise StockException(stock=self) from e
    

    What I want to achieve is to create a class object that would initialize a single stock object or a collection of stock objects. So I did a 'Stocks' and a 'Stock' object.

    'Stocks' here initializes a group of 'AStock' objects.

    @dataclass
    class Stocks:
        
        code_: List[str]
        force_update_: bool = False
        ticker_: str = field(init=False)
        symbol_: str = field(init=False)
        name_: str = field(init=False)
        sector_: str = field(init=False)
        subsector_: str = field(init=False)
        
        @exception(logger)
        def __post_init__(self) -> None:
            self.ticker_ = [indexer(code, arg='ticker') for code in self.code_]
            self.symbol_ = [indexer(code, arg='symbol') for code in self.code_]
            self.name_ = [indexer(code, arg='full_name') for code in self.code_]
            self.sector_ = [indexer(code, arg='sector') for code in self.code_]
            self.subsector_ = [indexer(code, arg='subsector') for code in self.code_]
        
        def __repr__(self) -> str:
            return ', '.join([f'{i[0]}:{i[1]}' for i in list(zip(self.code_, self.ticker_))])
        
        def __str__(self) -> str:
            return ', '.join([f'{i[0]}:{i[1]}' for i in list(zip(self.code_, self.ticker_))])
    
    

    and this 'Stock' object here is to handle the creation of 'AStock' or 'Stocks' object.

    @dataclass
    class Stock:
        code: Union[str, int, List[str]]
        force_update: bool = False
        
        @exception(logger)
        def __new__(cls, code, force_update: bool = False):
            if type(code) in [str, int]:
                return AStock(code, force_update)
            
            elif type(code) in [list]:
                return Stocks(code, force_update)
            
            else:
                raise ValueError('Not a valid stock code')
    

    So for example: If Stock(['1203', '1232']) will create Stocks object and Stock('1203') will create a AStock object. Just by providing arguments as a List or String it could detect whether to create AStock for single stock or Stocks for multiple stocks.

    However, this is pretty 'hacky' way of using __new__ to return an either AStock object or Stocks object. Is there a more elegant way of doing this?

    opened by mrkgoh 0
Owner
null
Original implementation of the pooling method introduced in "Speaker embeddings by modeling channel-wise correlations"

Speaker-Embeddings-Correlation-Pooling This is the original implementation of the pooling method introduced in "Speaker embeddings by modeling channel

Themos Stafylakis 10 Apr 30, 2022
Official PyTorch code for ClipBERT, an efficient framework for end-to-end learning on image-text and video-text tasks

Official PyTorch code for ClipBERT, an efficient framework for end-to-end learning on image-text and video-text tasks. It takes raw videos/images + text as inputs, and outputs task predictions. ClipBERT is designed based on 2D CNNs and transformers, and uses a sparse sampling strategy to enable efficient end-to-end video-and-language learning.

Jie Lei 雷杰 612 Jan 4, 2023
This code extends the neural style transfer image processing technique to video by generating smooth transitions between several reference style images

Neural Style Transfer Transition Video Processing By Brycen Westgarth and Tristan Jogminas Description This code extends the neural style transfer ima

Brycen Westgarth 110 Jan 7, 2023
Training code of Spatial Time Memory Network. Semi-supervised video object segmentation.

Training-code-of-STM This repository fully reproduces Space-Time Memory Networks Performance on Davis17 val set&Weights backbone training stage traini

haochen wang 128 Dec 11, 2022
An official implementation for "CLIP4Clip: An Empirical Study of CLIP for End to End Video Clip Retrieval"

The implementation of paper CLIP4Clip: An Empirical Study of CLIP for End to End Video Clip Retrieval. CLIP4Clip is a video-text retrieval model based

ArrowLuo 456 Jan 6, 2023
Code examples for my Write Better Python Code series on YouTube.

Write Better Python Code This repository contains the code examples used in my Write Better Python Code series published on YouTube: https:/

null 858 Dec 29, 2022
A python script to prefab your scripts/text files, and re create them with ease and not have to open your browser to copy code or write code yourself

Scriptfab - What is it? A python script to prefab your scripts/text files, and re create them with ease and not have to open your browser to copy code

DevNugget 3 Jul 28, 2021
Code-autocomplete, a code completion plugin for Python

Code AutoComplete code-autocomplete, a code completion plugin for Python.

xuming 13 Jan 7, 2023
Code to use Augmented Shapiro Wilks Stopping, as well as code for the paper "Statistically Signifigant Stopping of Neural Network Training"

This codebase is being actively maintained, please create and issue if you have issues using it Basics All data files are included under losses and ea

Justin Terry 32 Nov 9, 2021