Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Implements `_.method()`

オープン
#46 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
python

調査の方向性

Issue に示されている Callable.getattr の実装から始め、提案されている中間 Attr クラスと比較します。.method() と、1つの引数を受け取るメソッドについて意図された動作を確認し、その結果得られる API が属性アクセスとメソッド呼び出しの両方を曖昧さなく処理できることを確認します。

索引モデルが issue の本文から書いたものです。

説明

I'm opening this issue to discuss the possible ways to implement _.method()

Currently, we have this implementation:

class _Callable(object):
    def __getattr__(
        self,
        key: str,
    ) -> Callable[[_LambdaDynamicProtocol[T1]], T1]:
        return operator.attrgetter(key)

The problem here is that we return the operator directly:

>>> from lambdas import _
>>> _.method
operator.attrgetter('method')
>>> _.method()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: attrgetter expected 1 arguments, got 0

My idea is to create an intermediated class like _MathExpression:

class Attr:  # Just ignore the name for now
    def __init__(self, attr: str) -> None:
        self._attrgetter = operator.attrgetter(attr)

    def __call__(self, *args, **kwargs) -> Any:
        if len(args) == 1:
            return self._attrgetter(args[0])
        return lambda obj: self._attrgetter(obj)(*args, **kwargs)

This implementation has a limitation, they won't work correctly if we try to call a method with one argument. This is hard because we don't know when the attribute is callable!

主要言語
Python
スター
286
フォーク
6
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dry-python/lambdas のほかの issue

dry-python/lambdas の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。